<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>


<script language="javascript">
	function addRow(tableID)
	{
		var table=document.getElementById(tableID); //table id
		var rowCount=table.rows.length;
		var row=table.insertRow(rowCount); //row count of table
		var colCount=table.rows[0].cells.length; // column count
		
		for(var i=0;i<colCount;i++)
		{
			var newcell=row.insertCell(i);
			newcell.innerHTML=table.rows[0].cells[i].innerHTML;
			
			switch(newcell.childNodes[0].type)
			{
				case"text":newcell.childNodes[0].value="";
					break;
				case"checkbox":newcell.childNodes[0].checked=false;
					break;
				case"select-one":newcell.childNodes[0].selectedIndex=0;break;
			}
			
			var newcell=row.insertCell(i+1);
			newcell.innerHTML=table.rows[0].cells[i+1].innerHTML;
			
			switch(newcell.childNodes[0].type)
			{
				case"text":newcell.childNodes[0].value="";
					break;
				case"checkbox":newcell.childNodes[0].checked=false;
					break;
				case"label":newcell.childNodes[0].selectedIndex=0;break;
			}
		}
	}
	
	function deleteRow(tableID)
	{
		try
		{
			var table=document.getElementById(tableID);
			var rowCount=table.rows.length;
			
			for(var i=0;i<rowCount;i++)
			{
				var row=table.rows[i];
				var chkbox=row.cells[0].childNodes[0];
				
				if(null!=chkbox&&true==chkbox.checked)
				{
					if(rowCount<=1)
					{
						alert("Cannot delete all the rows.");
						break;
					}
					
					table.deleteRow(i);rowCount--;i--;
				}
			}
		}catch(e)
		{
			alert(e);
		}
	}
	
	</script>
	
 <%--
<script language=javascript>
function addrows()
{
	
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.value="";
element1.id="empName[0]";
element1.name="empName[0]";

cell1.appendChild(element1); 
}
</script>
--%>

</head>
<body>
 
 
    <input type="button" value="Add Row" onclick="addRow('dataTable')">
 
    <input type="button" value="Delete Row" onclick="deleteRow('dataTable')">
 
     <table id="dataTable" width="350px" border="1">
        <tbody><tr>
            <td><input type="checkbox" name="chk"></td>
            <td><input type="text" name="txt"></td>
            <td>
                <select name="country">
                    <option value="in">India</option>
                    <option value="de">Germany</option>
                    <option value="fr">France</option>
                    <option value="us">United States</option>
                    <option value="ch">Switzerland</option>
                </select>
            </td>
        </tr>
        <tr>
        	<td> <input type="checkbox"> </td>
        	<td> <label>Account: </label></td>
        	<td> <input type="text" > </td>
        </tr>
    </tbody></table>
</body>
</html>